#include "StdAfx.h"
#include "BaseObject.h"
#include <wchar.h>

unsigned long CBaseObject::s_uIndex = 0;
CBaseObject::CBaseObject(void)
{
	printFunName();
	m_uIndex = s_uIndex++;
	std::cout<<"index = "<<m_uIndex<<std::endl;
}


CBaseObject::~CBaseObject(void)
{
	printFunName();
	std::cout<<"index = "<<m_uIndex<<std::endl;
}
//////////////////////////////////////////////////////////////////////////
//								CMyString
//////////////////////////////////////////////////////////////////////////
CMyString::CMyString():
	m_pszData(NULL)
{
	printFunName();
}

CMyString::CMyString( const wchar_t* const psz ):
	m_pszData(NULL)
{
	printFunName();
	if (psz != NULL)
	{
		m_pszData = new wchar_t[wcslen(psz)+1];
		wcscpy(m_pszData, psz);
	}
	else
		m_pszData = NULL;
}

CMyString::CMyString( const CMyString& myStr ):
	m_pszData(NULL)
{
	printFunName();
	if (m_pszData)
	{
		FreeData();
	}
	InitData(myStr.m_pszData);
}

CMyString::~CMyString()
{
	printFunName();
	if (m_pszData)
	{
		delete m_pszData;
		m_pszData = NULL;
	}
}

CMyString & CMyString::operator=( const CMyString &myStr )
{
	printFunName();
	FreeData();
	InitData(myStr);
	return *this;
}

void CMyString::FreeData()
{
	printFunName();
	delete m_pszData;
	m_pszData = NULL;
}

void CMyString::InitData( const wchar_t* const psz )
{
	printFunName();
	if (psz != NULL)
	{
		m_pszData = new wchar_t[wcslen(psz)+1];
		wcscpy(m_pszData, psz);
	}
	else
		m_pszData = NULL;
}

CMyString::operator const wchar_t*()const
{
	printFunName();
	if (m_pszData)
	{
		return m_pszData;
	}
	else
		return NULL;
}

CMyString CMyString::operator+( const wchar_t* const psz )
{
	printFunName();
	CMyString myStrTemp(m_pszData);
	myStrTemp.Append(psz);
	return myStrTemp;
}

CMyString CMyString::operator+( const CMyString &myStr )
{
	printFunName();
	CMyString myStrTemp(m_pszData);
	myStrTemp.Append(myStr.m_pszData);
	return myStrTemp;
}

void CMyString::Append( const wchar_t* const psz )
{
	printFunName();
	if (psz)
	{
		if (!m_pszData)
		{
			InitData(psz);
		}
		else
		{
			int nLength = wcslen(m_pszData);
			nLength += wcslen(psz);
			wchar_t *pszTemp = new wchar_t[nLength+1];
			wsprintf(pszTemp, L"%s%s", m_pszData, psz);
			delete m_pszData;
			InitData(pszTemp);
		}
	}
}

CMyString & CMyString::operator+=( const wchar_t* const psz )
{
	printFunName();
	this->Append(psz);
	return *this;
}

CMyString & CMyString::operator+=( const CMyString &myStr )
{
	printFunName();
	this->Append(myStr.m_pszData);
	return *this;
}

bool CMyString::operator==( const wchar_t* const psz )
{
	printFunName();
	if (wcscmp(m_pszData, psz) == 0)
	{
		return true;
	}
	return false;
}

bool CMyString::operator==( const CMyString &myStr )
{
	printFunName();
	if (wcscmp(m_pszData, myStr.m_pszData) == 0)
	{
		return true;
	}
	return false;
}

bool CMyString::CompareNoCase( const wchar_t* const psz )
{
	printFunName();
	if (wcsicmp(m_pszData, psz) == 0)
	{
		return true;
	}
	return false;
}

bool CMyString::CompareNoCase( const CMyString &myStr )
{
	printFunName();
	if (wcsicmp(m_pszData, myStr.m_pszData) == 0)
	{
		return true;
	}
	return false;
}
